<?php
require_once '../libs/app.config.php';
session_start();
if($_SESSION['LoginId'] == false){
	header("Location:login.php");
}
$tpn = new Page();
//分类列表
$sql="select id, value_type, value_info from setting_value where value_type = 'status' order by value_info";
$query=$tpm->query($sql);
$totals=$tpm->num_rows($query);
	$tpn->pageft($totals,15);
	$result=$tpm->query($sql." limit ".$tpn->getfirstcount().",15");

while($rows=$tpm->fetch_array($result))
{
$status_list[]=array('id'=>$rows['id'],
			     'value_info'=>$rows['value_info']);
}

//多项删除
if($_POST['submit'])
{
	if(!empty($_POST['check']))
	{
		$array=$_POST['check'];
		$arr=implode(',',$array);
		$id=explode(',',$arr);
		$size=count($id);
		for($j=0;$j<$size;$j++)
		{
			$sql1="delete from setting_value where id= '".$id[$j]."'";
			$query1=$tpm->query($sql1);
			
			if($query1>0)
			echo "<script>alert('Deletion is completed');location.href=('status_values_list.php');</script>";
		}
	}
}

//单项删除
if($_POST["delid"])
{
  $sql= "delete from setting_value where id= '".$_POST['delid']."'";
  $query1=$tpm->query($sql);  
  if($tpm->affected_rows($query1))
  echo "1";
  else
  echo "0";
}

// 添加新Location
if ($_POST ['submit'] && $_GET ['act'] == 'add') {
	$value_type = "status";
	$add = array (
			"value_type" => $value_type,
			"value_info" => $value_info
	);

	$result = $tpm->insert ( "setting_value", $add );
	if ($result > 0)
		echo "<script>alert('Status added successfully');location.href=('status_values_list.php');</script>";
}

require_once(INCLUDE_PATH.'template.inc.php');  //模板类及对象$tpl的加载
    $tpl->assign("status_list",$status_list);
    $tpl->assign("status",$status);
	$tpl->assign('pages',$tpn->getpagenav());
	$tpl->display("status_values_list.html");
?>